import request from "@/utils/request";
import type{
    DictTypeQuery,
    DictTypePageResult,
    DictTypeForm,
    DictQuery,
    DictForm,
    DictPageResult,
  } from "./model";
import type { OptionType } from "element-plus/es/components/select-v2/src/select.types.mjs";


/**
   * 字典类型分页列表
   *
   * @param queryParams
   */
export function getDictTypePage(queryParams:DictTypeQuery){
    return request<any,DictPageResult>({
        url:'/api/v1/dict/types/page',
        method:'get',
        params:queryParams,
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

/**
   * 字典类型表单数据
   *
   * @param id
   */
export function getDictTypeForm(id:number){
    return request<any,ResponseData<DictTypeForm>>({
        url:`/api/v1/dict/types/` + id + `/form`,
        method:'get',
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

  /**
   * 新增字典类型
   *
   * @param data
   */
export function addDictType(data:DictTypeForm){
    return request({
        url:'/api/v1/dict/types',
        method:'post',
        data:data,
        headers:{
            "Content-Type":"application/json"
        }
    })
}

 /**
   * 修改字典类型
   *
   * @param id
   * @param data
   */
 export function updateDictType(id:number,data:DictTypeForm){
    return request({
        url:'/api/v1/dict/types/' + id,
        method:'put',
        data:data,
        headers:{
            "Content-Type":"application/json"
        }
    })
}

  /**
   * 删除字典类型
   */
export function deleteDictTypes(ids:string){
    return request({
        url:'/api/v1/dict/types/' + ids,
        method:'delete',
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

/**
   * 获取字典类型的数据项
   *
   * @param typeCode 字典类型编码
   */
export function getDictOptions(typeCode:string){
    return request<any,OptionType[]>({
        url:"/api/v1/dict/" + typeCode + "/options",
        method:'get',
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

 /**
   * 字典分页列表
   */
export function getDictPage(queryParams:DictQuery){
    return request<any,DictPageResult>({
        url:'/api/v1/dict/page',
        method:"get",
        params:queryParams,
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

/**
   * 获取字典表单数据
   *
   * @param id
   */
export function getDictFormData(id:number){
    return request<any,DictForm>({
        url:'/api/v1/dict/' + id + '/form',
        method:"get",
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

/**
   * 新增字典
   *
   * @param data
   */
export function addDict(data:DictForm){
    return request({
        url:'/api/v1/dict',
        method:"post",
        data:data,
        headers:{
            "Content-Type":"application/json"
        }
    })
}

/**
   * 修改字典项
   *
   * @param id
   * @param data
   */
export function updateDict(id:number,data:DictForm){
    return request({
        url:'/api/v1/dict/' + id,
        method:"put",
        data:data,
        headers:{
            "Content-Type":"application/json"
        }
    })
}

 /**
   * 删除字典
   *
   * @param ids 字典项ID，多个以英文逗号(,)分割
   */
 export function deleteDictByIds(ids:string){
    return request({
        url:'/api/v1/dict/' + ids,
        method:"delete",
        headers:{
            "Content-Type":"application/json"
        }
    })
}
